
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 04/25/2013 00:32:45
-- Generated from EDMX file: C:\Users\stefan\Google Drive\SU Sofia\Master\Semester Two\Software Technologies - Project\HRS\HRS\HotelRegistrationSystem\HotelRegistrationSystem.DAL\HotelRegistrationSystemModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [HotelRegistration];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_Hotel_Address]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Hotels] DROP CONSTRAINT [FK_Hotel_Address];
GO
IF OBJECT_ID(N'[dbo].[FK_Hotel_HotelType]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Hotels] DROP CONSTRAINT [FK_Hotel_HotelType];
GO
IF OBJECT_ID(N'[dbo].[FK_Hotel_PaymentType]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Hotels] DROP CONSTRAINT [FK_Hotel_PaymentType];
GO
IF OBJECT_ID(N'[dbo].[FK_HotelsRatings_Hotel]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[HotelsRatings] DROP CONSTRAINT [FK_HotelsRatings_Hotel];
GO
IF OBJECT_ID(N'[dbo].[FK_HotelsRoomsPictures_Hotel]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[HotelsRoomsPictures] DROP CONSTRAINT [FK_HotelsRoomsPictures_Hotel];
GO
IF OBJECT_ID(N'[dbo].[FK_Rooms_Hotel]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Rooms] DROP CONSTRAINT [FK_Rooms_Hotel];
GO
IF OBJECT_ID(N'[dbo].[FK_HotelsRoomsPictures_Room]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[HotelsRoomsPictures] DROP CONSTRAINT [FK_HotelsRoomsPictures_Room];
GO
IF OBJECT_ID(N'[dbo].[FK_Rooms_RoomType]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Rooms] DROP CONSTRAINT [FK_Rooms_RoomType];
GO
IF OBJECT_ID(N'[dbo].[FK_HotelsFacilities_Facility]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[HotelsFacilities] DROP CONSTRAINT [FK_HotelsFacilities_Facility];
GO
IF OBJECT_ID(N'[dbo].[FK_HotelsFacilities_Hotel]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[HotelsFacilities] DROP CONSTRAINT [FK_HotelsFacilities_Hotel];
GO
IF OBJECT_ID(N'[dbo].[FK_ReservationsRooms_Reservation]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ReservationsRooms] DROP CONSTRAINT [FK_ReservationsRooms_Reservation];
GO
IF OBJECT_ID(N'[dbo].[FK_ReservationsRooms_Room]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ReservationsRooms] DROP CONSTRAINT [FK_ReservationsRooms_Room];
GO
IF OBJECT_ID(N'[dbo].[FK_RoomsFacilities_Facility]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RoomsFacilities] DROP CONSTRAINT [FK_RoomsFacilities_Facility];
GO
IF OBJECT_ID(N'[dbo].[FK_RoomsFacilities_Room]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RoomsFacilities] DROP CONSTRAINT [FK_RoomsFacilities_Room];
GO
IF OBJECT_ID(N'[dbo].[FK_Users_Address]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Users] DROP CONSTRAINT [FK_Users_Address];
GO
IF OBJECT_ID(N'[dbo].[FK_Hotel_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Hotels] DROP CONSTRAINT [FK_Hotel_User];
GO
IF OBJECT_ID(N'[dbo].[FK_HotelsRatings_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[HotelsRatings] DROP CONSTRAINT [FK_HotelsRatings_User];
GO
IF OBJECT_ID(N'[dbo].[FK_Reservations_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Reservations] DROP CONSTRAINT [FK_Reservations_User];
GO
IF OBJECT_ID(N'[dbo].[FK_Users_UserType]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Users] DROP CONSTRAINT [FK_Users_UserType];
GO
IF OBJECT_ID(N'[dbo].[FK_UserRoomLikes_Room]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserRoomLikes] DROP CONSTRAINT [FK_UserRoomLikes_Room];
GO
IF OBJECT_ID(N'[dbo].[FK_UserRoomLikes_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserRoomLikes] DROP CONSTRAINT [FK_UserRoomLikes_User];
GO
IF OBJECT_ID(N'[dbo].[FK_UserRoomViews_Room]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserRoomViews] DROP CONSTRAINT [FK_UserRoomViews_Room];
GO
IF OBJECT_ID(N'[dbo].[FK_UserRoomViews_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserRoomViews] DROP CONSTRAINT [FK_UserRoomViews_User];
GO
IF OBJECT_ID(N'[dbo].[FK_webpages_UsersInRoles_webpages_Roles]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[webpages_UsersInRoles] DROP CONSTRAINT [FK_webpages_UsersInRoles_webpages_Roles];
GO
IF OBJECT_ID(N'[dbo].[FK_webpages_UsersInRoles_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[webpages_UsersInRoles] DROP CONSTRAINT [FK_webpages_UsersInRoles_User];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[sysdiagrams]', 'U') IS NOT NULL
    DROP TABLE [dbo].[sysdiagrams];
GO
IF OBJECT_ID(N'[dbo].[webpages_Membership]', 'U') IS NOT NULL
    DROP TABLE [dbo].[webpages_Membership];
GO
IF OBJECT_ID(N'[dbo].[webpages_OAuthMembership]', 'U') IS NOT NULL
    DROP TABLE [dbo].[webpages_OAuthMembership];
GO
IF OBJECT_ID(N'[dbo].[webpages_Roles]', 'U') IS NOT NULL
    DROP TABLE [dbo].[webpages_Roles];
GO
IF OBJECT_ID(N'[dbo].[Addresses]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Addresses];
GO
IF OBJECT_ID(N'[dbo].[Facilities]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Facilities];
GO
IF OBJECT_ID(N'[dbo].[Hotels]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Hotels];
GO
IF OBJECT_ID(N'[dbo].[HotelsRatings]', 'U') IS NOT NULL
    DROP TABLE [dbo].[HotelsRatings];
GO
IF OBJECT_ID(N'[dbo].[HotelsRoomsPictures]', 'U') IS NOT NULL
    DROP TABLE [dbo].[HotelsRoomsPictures];
GO
IF OBJECT_ID(N'[dbo].[HotelTypes]', 'U') IS NOT NULL
    DROP TABLE [dbo].[HotelTypes];
GO
IF OBJECT_ID(N'[dbo].[PaymentTypes]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PaymentTypes];
GO
IF OBJECT_ID(N'[dbo].[Reservations]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Reservations];
GO
IF OBJECT_ID(N'[dbo].[Rooms]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Rooms];
GO
IF OBJECT_ID(N'[dbo].[RoomTypes]', 'U') IS NOT NULL
    DROP TABLE [dbo].[RoomTypes];
GO
IF OBJECT_ID(N'[dbo].[UserTypes]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserTypes];
GO
IF OBJECT_ID(N'[dbo].[Users]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Users];
GO
IF OBJECT_ID(N'[dbo].[HotelsFacilities]', 'U') IS NOT NULL
    DROP TABLE [dbo].[HotelsFacilities];
GO
IF OBJECT_ID(N'[dbo].[ReservationsRooms]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ReservationsRooms];
GO
IF OBJECT_ID(N'[dbo].[RoomsFacilities]', 'U') IS NOT NULL
    DROP TABLE [dbo].[RoomsFacilities];
GO
IF OBJECT_ID(N'[dbo].[UserRoomLikes]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserRoomLikes];
GO
IF OBJECT_ID(N'[dbo].[UserRoomViews]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserRoomViews];
GO
IF OBJECT_ID(N'[dbo].[webpages_UsersInRoles]', 'U') IS NOT NULL
    DROP TABLE [dbo].[webpages_UsersInRoles];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'sysdiagrams'
CREATE TABLE [dbo].[sysdiagrams] (
    [name] nvarchar(128)  NOT NULL,
    [principal_id] int  NOT NULL,
    [diagram_id] int IDENTITY(1,1) NOT NULL,
    [version] int  NULL,
    [definition] varbinary(max)  NULL
);
GO

-- Creating table 'webpages_Membership'
CREATE TABLE [dbo].[webpages_Membership] (
    [UserId] int  NOT NULL,
    [CreateDate] datetime  NULL,
    [ConfirmationToken] nvarchar(128)  NULL,
    [IsConfirmed] bit  NULL,
    [LastPasswordFailureDate] datetime  NULL,
    [PasswordFailuresSinceLastSuccess] int  NOT NULL,
    [Password] nvarchar(128)  NOT NULL,
    [PasswordChangedDate] datetime  NULL,
    [PasswordSalt] nvarchar(128)  NOT NULL,
    [PasswordVerificationToken] nvarchar(128)  NULL,
    [PasswordVerificationTokenExpirationDate] datetime  NULL
);
GO

-- Creating table 'webpages_OAuthMembership'
CREATE TABLE [dbo].[webpages_OAuthMembership] (
    [Provider] nvarchar(30)  NOT NULL,
    [ProviderUserId] nvarchar(100)  NOT NULL,
    [UserId] int  NOT NULL
);
GO

-- Creating table 'webpages_Roles'
CREATE TABLE [dbo].[webpages_Roles] (
    [RoleId] int IDENTITY(1,1) NOT NULL,
    [RoleName] nvarchar(256)  NOT NULL
);
GO

-- Creating table 'Addresses'
CREATE TABLE [dbo].[Addresses] (
    [AddressId] int  NOT NULL,
    [Region] nvarchar(256)  NULL,
    [PostCode] nvarchar(64)  NULL,
    [Country] nvarchar(128)  NOT NULL,
    [City] nvarchar(128)  NOT NULL,
    [Street] nvarchar(128)  NOT NULL
);
GO

-- Creating table 'Facilities'
CREATE TABLE [dbo].[Facilities] (
    [ForHotel] int  NOT NULL,
    [FacilityId] int  NOT NULL,
    [Description] nvarchar(128)  NOT NULL
);
GO

-- Creating table 'Hotels'
CREATE TABLE [dbo].[Hotels] (
    [HotelId] int  NOT NULL,
    [Name] nvarchar(256)  NOT NULL,
    [EarliestCheckIn] time  NULL,
    [LatestCheckOut] time  NULL,
    [AddressId] int  NOT NULL,
    [UserId] int  NOT NULL,
    [PhoneNumber] nvarchar(max)  NULL,
    [Email] nvarchar(64)  NULL,
    [HotelTypeId] int  NOT NULL,
    [Description] nvarchar(512)  NULL,
    [Earnest] decimal(18,2)  NULL,
    [ReservationDenyPeriod] int  NULL,
    [ContactPeriod] int  NULL,
    [PaymentTypeId] int  NOT NULL
);
GO

-- Creating table 'HotelsRatings'
CREATE TABLE [dbo].[HotelsRatings] (
    [HotelId] int  NOT NULL,
    [UserId] int  NOT NULL,
    [Rating] int  NOT NULL
);
GO

-- Creating table 'HotelsRoomsPictures'
CREATE TABLE [dbo].[HotelsRoomsPictures] (
    [PictureId] int  NOT NULL,
    [HotelId] int  NOT NULL,
    [RoomId] int  NULL,
    [PictureName] nvarchar(128)  NOT NULL
);
GO

-- Creating table 'HotelTypes'
CREATE TABLE [dbo].[HotelTypes] (
    [HotelTypeId] int  NOT NULL,
    [Description] nvarchar(256)  NULL,
    [Type] nvarchar(128)  NOT NULL
);
GO

-- Creating table 'PaymentTypes'
CREATE TABLE [dbo].[PaymentTypes] (
    [PaymentTypeId] int  NOT NULL,
    [Type] nvarchar(64)  NOT NULL
);
GO

-- Creating table 'Reservations'
CREATE TABLE [dbo].[Reservations] (
    [ReservationId] int  NOT NULL,
    [DateCreated] datetime  NOT NULL,
    [UserId] int  NOT NULL,
    [StartDate] datetime  NOT NULL,
    [Period] int  NOT NULL,
    [Denied] int  NULL
);
GO

-- Creating table 'Rooms'
CREATE TABLE [dbo].[Rooms] (
    [RoomId] int  NOT NULL,
    [HotelId] int  NOT NULL,
    [Name] nvarchar(128)  NULL,
    [Price] decimal(18,2)  NULL,
    [Description] nvarchar(512)  NULL,
    [RoomTypeId] int  NOT NULL,
    [BedCount] int  NOT NULL
);
GO

-- Creating table 'RoomTypes'
CREATE TABLE [dbo].[RoomTypes] (
    [RoomTypeId] int  NOT NULL,
    [Type] nvarchar(64)  NOT NULL
);
GO

-- Creating table 'UserTypes'
CREATE TABLE [dbo].[UserTypes] (
    [UserTypeId] int  NOT NULL,
    [Type] nvarchar(64)  NOT NULL
);
GO

-- Creating table 'Users'
CREATE TABLE [dbo].[Users] (
    [UserId] int IDENTITY(1,1) NOT NULL,
    [UserName] nvarchar(56)  NOT NULL,
    [Email] nvarchar(56)  NOT NULL,
    [FirstName] nvarchar(56)  NULL,
    [MiddleName] nvarchar(56)  NULL,
    [LastName] nvarchar(56)  NULL,
    [PhoneNumber] nvarchar(56)  NULL,
    [UserTypeId] int  NOT NULL,
    [AddressId] int  NULL,
    [EmailID] nvarchar(max)  NULL,
    [Details] nvarchar(max)  NULL
);
GO

-- Creating table 'HotelsFacilities'
CREATE TABLE [dbo].[HotelsFacilities] (
    [Facilities_FacilityId] int  NOT NULL,
    [Hotels_HotelId] int  NOT NULL
);
GO

-- Creating table 'ReservationsRooms'
CREATE TABLE [dbo].[ReservationsRooms] (
    [Reservations_ReservationId] int  NOT NULL,
    [Rooms_RoomId] int  NOT NULL
);
GO

-- Creating table 'RoomsFacilities'
CREATE TABLE [dbo].[RoomsFacilities] (
    [Facilities_FacilityId] int  NOT NULL,
    [Rooms_RoomId] int  NOT NULL
);
GO

-- Creating table 'UserRoomLikes'
CREATE TABLE [dbo].[UserRoomLikes] (
    [Rooms_RoomId] int  NOT NULL,
    [Users_UserId] int  NOT NULL
);
GO

-- Creating table 'UserRoomViews'
CREATE TABLE [dbo].[UserRoomViews] (
    [Rooms1_RoomId] int  NOT NULL,
    [Users1_UserId] int  NOT NULL
);
GO

-- Creating table 'webpages_UsersInRoles'
CREATE TABLE [dbo].[webpages_UsersInRoles] (
    [webpages_Roles_RoleId] int  NOT NULL,
    [Users_UserId] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [diagram_id] in table 'sysdiagrams'
ALTER TABLE [dbo].[sysdiagrams]
ADD CONSTRAINT [PK_sysdiagrams]
    PRIMARY KEY CLUSTERED ([diagram_id] ASC);
GO

-- Creating primary key on [UserId] in table 'webpages_Membership'
ALTER TABLE [dbo].[webpages_Membership]
ADD CONSTRAINT [PK_webpages_Membership]
    PRIMARY KEY CLUSTERED ([UserId] ASC);
GO

-- Creating primary key on [Provider], [ProviderUserId] in table 'webpages_OAuthMembership'
ALTER TABLE [dbo].[webpages_OAuthMembership]
ADD CONSTRAINT [PK_webpages_OAuthMembership]
    PRIMARY KEY CLUSTERED ([Provider], [ProviderUserId] ASC);
GO

-- Creating primary key on [RoleId] in table 'webpages_Roles'
ALTER TABLE [dbo].[webpages_Roles]
ADD CONSTRAINT [PK_webpages_Roles]
    PRIMARY KEY CLUSTERED ([RoleId] ASC);
GO

-- Creating primary key on [AddressId] in table 'Addresses'
ALTER TABLE [dbo].[Addresses]
ADD CONSTRAINT [PK_Addresses]
    PRIMARY KEY CLUSTERED ([AddressId] ASC);
GO

-- Creating primary key on [FacilityId] in table 'Facilities'
ALTER TABLE [dbo].[Facilities]
ADD CONSTRAINT [PK_Facilities]
    PRIMARY KEY CLUSTERED ([FacilityId] ASC);
GO

-- Creating primary key on [HotelId] in table 'Hotels'
ALTER TABLE [dbo].[Hotels]
ADD CONSTRAINT [PK_Hotels]
    PRIMARY KEY CLUSTERED ([HotelId] ASC);
GO

-- Creating primary key on [HotelId], [UserId] in table 'HotelsRatings'
ALTER TABLE [dbo].[HotelsRatings]
ADD CONSTRAINT [PK_HotelsRatings]
    PRIMARY KEY CLUSTERED ([HotelId], [UserId] ASC);
GO

-- Creating primary key on [PictureId] in table 'HotelsRoomsPictures'
ALTER TABLE [dbo].[HotelsRoomsPictures]
ADD CONSTRAINT [PK_HotelsRoomsPictures]
    PRIMARY KEY CLUSTERED ([PictureId] ASC);
GO

-- Creating primary key on [HotelTypeId] in table 'HotelTypes'
ALTER TABLE [dbo].[HotelTypes]
ADD CONSTRAINT [PK_HotelTypes]
    PRIMARY KEY CLUSTERED ([HotelTypeId] ASC);
GO

-- Creating primary key on [PaymentTypeId] in table 'PaymentTypes'
ALTER TABLE [dbo].[PaymentTypes]
ADD CONSTRAINT [PK_PaymentTypes]
    PRIMARY KEY CLUSTERED ([PaymentTypeId] ASC);
GO

-- Creating primary key on [ReservationId] in table 'Reservations'
ALTER TABLE [dbo].[Reservations]
ADD CONSTRAINT [PK_Reservations]
    PRIMARY KEY CLUSTERED ([ReservationId] ASC);
GO

-- Creating primary key on [RoomId] in table 'Rooms'
ALTER TABLE [dbo].[Rooms]
ADD CONSTRAINT [PK_Rooms]
    PRIMARY KEY CLUSTERED ([RoomId] ASC);
GO

-- Creating primary key on [RoomTypeId] in table 'RoomTypes'
ALTER TABLE [dbo].[RoomTypes]
ADD CONSTRAINT [PK_RoomTypes]
    PRIMARY KEY CLUSTERED ([RoomTypeId] ASC);
GO

-- Creating primary key on [UserTypeId] in table 'UserTypes'
ALTER TABLE [dbo].[UserTypes]
ADD CONSTRAINT [PK_UserTypes]
    PRIMARY KEY CLUSTERED ([UserTypeId] ASC);
GO

-- Creating primary key on [UserId] in table 'Users'
ALTER TABLE [dbo].[Users]
ADD CONSTRAINT [PK_Users]
    PRIMARY KEY CLUSTERED ([UserId] ASC);
GO

-- Creating primary key on [Facilities_FacilityId], [Hotels_HotelId] in table 'HotelsFacilities'
ALTER TABLE [dbo].[HotelsFacilities]
ADD CONSTRAINT [PK_HotelsFacilities]
    PRIMARY KEY NONCLUSTERED ([Facilities_FacilityId], [Hotels_HotelId] ASC);
GO

-- Creating primary key on [Reservations_ReservationId], [Rooms_RoomId] in table 'ReservationsRooms'
ALTER TABLE [dbo].[ReservationsRooms]
ADD CONSTRAINT [PK_ReservationsRooms]
    PRIMARY KEY NONCLUSTERED ([Reservations_ReservationId], [Rooms_RoomId] ASC);
GO

-- Creating primary key on [Facilities_FacilityId], [Rooms_RoomId] in table 'RoomsFacilities'
ALTER TABLE [dbo].[RoomsFacilities]
ADD CONSTRAINT [PK_RoomsFacilities]
    PRIMARY KEY NONCLUSTERED ([Facilities_FacilityId], [Rooms_RoomId] ASC);
GO

-- Creating primary key on [Rooms_RoomId], [Users_UserId] in table 'UserRoomLikes'
ALTER TABLE [dbo].[UserRoomLikes]
ADD CONSTRAINT [PK_UserRoomLikes]
    PRIMARY KEY NONCLUSTERED ([Rooms_RoomId], [Users_UserId] ASC);
GO

-- Creating primary key on [Rooms1_RoomId], [Users1_UserId] in table 'UserRoomViews'
ALTER TABLE [dbo].[UserRoomViews]
ADD CONSTRAINT [PK_UserRoomViews]
    PRIMARY KEY NONCLUSTERED ([Rooms1_RoomId], [Users1_UserId] ASC);
GO

-- Creating primary key on [webpages_Roles_RoleId], [Users_UserId] in table 'webpages_UsersInRoles'
ALTER TABLE [dbo].[webpages_UsersInRoles]
ADD CONSTRAINT [PK_webpages_UsersInRoles]
    PRIMARY KEY NONCLUSTERED ([webpages_Roles_RoleId], [Users_UserId] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [AddressId] in table 'Hotels'
ALTER TABLE [dbo].[Hotels]
ADD CONSTRAINT [FK_Hotel_Address]
    FOREIGN KEY ([AddressId])
    REFERENCES [dbo].[Addresses]
        ([AddressId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Hotel_Address'
CREATE INDEX [IX_FK_Hotel_Address]
ON [dbo].[Hotels]
    ([AddressId]);
GO

-- Creating foreign key on [HotelTypeId] in table 'Hotels'
ALTER TABLE [dbo].[Hotels]
ADD CONSTRAINT [FK_Hotel_HotelType]
    FOREIGN KEY ([HotelTypeId])
    REFERENCES [dbo].[HotelTypes]
        ([HotelTypeId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Hotel_HotelType'
CREATE INDEX [IX_FK_Hotel_HotelType]
ON [dbo].[Hotels]
    ([HotelTypeId]);
GO

-- Creating foreign key on [PaymentTypeId] in table 'Hotels'
ALTER TABLE [dbo].[Hotels]
ADD CONSTRAINT [FK_Hotel_PaymentType]
    FOREIGN KEY ([PaymentTypeId])
    REFERENCES [dbo].[PaymentTypes]
        ([PaymentTypeId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Hotel_PaymentType'
CREATE INDEX [IX_FK_Hotel_PaymentType]
ON [dbo].[Hotels]
    ([PaymentTypeId]);
GO

-- Creating foreign key on [HotelId] in table 'HotelsRatings'
ALTER TABLE [dbo].[HotelsRatings]
ADD CONSTRAINT [FK_HotelsRatings_Hotel]
    FOREIGN KEY ([HotelId])
    REFERENCES [dbo].[Hotels]
        ([HotelId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [HotelId] in table 'HotelsRoomsPictures'
ALTER TABLE [dbo].[HotelsRoomsPictures]
ADD CONSTRAINT [FK_HotelsRoomsPictures_Hotel]
    FOREIGN KEY ([HotelId])
    REFERENCES [dbo].[Hotels]
        ([HotelId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_HotelsRoomsPictures_Hotel'
CREATE INDEX [IX_FK_HotelsRoomsPictures_Hotel]
ON [dbo].[HotelsRoomsPictures]
    ([HotelId]);
GO

-- Creating foreign key on [HotelId] in table 'Rooms'
ALTER TABLE [dbo].[Rooms]
ADD CONSTRAINT [FK_Rooms_Hotel]
    FOREIGN KEY ([HotelId])
    REFERENCES [dbo].[Hotels]
        ([HotelId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Rooms_Hotel'
CREATE INDEX [IX_FK_Rooms_Hotel]
ON [dbo].[Rooms]
    ([HotelId]);
GO

-- Creating foreign key on [RoomId] in table 'HotelsRoomsPictures'
ALTER TABLE [dbo].[HotelsRoomsPictures]
ADD CONSTRAINT [FK_HotelsRoomsPictures_Room]
    FOREIGN KEY ([RoomId])
    REFERENCES [dbo].[Rooms]
        ([RoomId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_HotelsRoomsPictures_Room'
CREATE INDEX [IX_FK_HotelsRoomsPictures_Room]
ON [dbo].[HotelsRoomsPictures]
    ([RoomId]);
GO

-- Creating foreign key on [RoomTypeId] in table 'Rooms'
ALTER TABLE [dbo].[Rooms]
ADD CONSTRAINT [FK_Rooms_RoomType]
    FOREIGN KEY ([RoomTypeId])
    REFERENCES [dbo].[RoomTypes]
        ([RoomTypeId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Rooms_RoomType'
CREATE INDEX [IX_FK_Rooms_RoomType]
ON [dbo].[Rooms]
    ([RoomTypeId]);
GO

-- Creating foreign key on [Facilities_FacilityId] in table 'HotelsFacilities'
ALTER TABLE [dbo].[HotelsFacilities]
ADD CONSTRAINT [FK_HotelsFacilities_Facility]
    FOREIGN KEY ([Facilities_FacilityId])
    REFERENCES [dbo].[Facilities]
        ([FacilityId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Hotels_HotelId] in table 'HotelsFacilities'
ALTER TABLE [dbo].[HotelsFacilities]
ADD CONSTRAINT [FK_HotelsFacilities_Hotel]
    FOREIGN KEY ([Hotels_HotelId])
    REFERENCES [dbo].[Hotels]
        ([HotelId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_HotelsFacilities_Hotel'
CREATE INDEX [IX_FK_HotelsFacilities_Hotel]
ON [dbo].[HotelsFacilities]
    ([Hotels_HotelId]);
GO

-- Creating foreign key on [Reservations_ReservationId] in table 'ReservationsRooms'
ALTER TABLE [dbo].[ReservationsRooms]
ADD CONSTRAINT [FK_ReservationsRooms_Reservation]
    FOREIGN KEY ([Reservations_ReservationId])
    REFERENCES [dbo].[Reservations]
        ([ReservationId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Rooms_RoomId] in table 'ReservationsRooms'
ALTER TABLE [dbo].[ReservationsRooms]
ADD CONSTRAINT [FK_ReservationsRooms_Room]
    FOREIGN KEY ([Rooms_RoomId])
    REFERENCES [dbo].[Rooms]
        ([RoomId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ReservationsRooms_Room'
CREATE INDEX [IX_FK_ReservationsRooms_Room]
ON [dbo].[ReservationsRooms]
    ([Rooms_RoomId]);
GO

-- Creating foreign key on [Facilities_FacilityId] in table 'RoomsFacilities'
ALTER TABLE [dbo].[RoomsFacilities]
ADD CONSTRAINT [FK_RoomsFacilities_Facility]
    FOREIGN KEY ([Facilities_FacilityId])
    REFERENCES [dbo].[Facilities]
        ([FacilityId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Rooms_RoomId] in table 'RoomsFacilities'
ALTER TABLE [dbo].[RoomsFacilities]
ADD CONSTRAINT [FK_RoomsFacilities_Room]
    FOREIGN KEY ([Rooms_RoomId])
    REFERENCES [dbo].[Rooms]
        ([RoomId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_RoomsFacilities_Room'
CREATE INDEX [IX_FK_RoomsFacilities_Room]
ON [dbo].[RoomsFacilities]
    ([Rooms_RoomId]);
GO

-- Creating foreign key on [AddressId] in table 'Users'
ALTER TABLE [dbo].[Users]
ADD CONSTRAINT [FK_Users_Address]
    FOREIGN KEY ([AddressId])
    REFERENCES [dbo].[Addresses]
        ([AddressId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Users_Address'
CREATE INDEX [IX_FK_Users_Address]
ON [dbo].[Users]
    ([AddressId]);
GO

-- Creating foreign key on [UserId] in table 'Hotels'
ALTER TABLE [dbo].[Hotels]
ADD CONSTRAINT [FK_Hotel_User]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[Users]
        ([UserId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Hotel_User'
CREATE INDEX [IX_FK_Hotel_User]
ON [dbo].[Hotels]
    ([UserId]);
GO

-- Creating foreign key on [UserId] in table 'HotelsRatings'
ALTER TABLE [dbo].[HotelsRatings]
ADD CONSTRAINT [FK_HotelsRatings_User]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[Users]
        ([UserId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_HotelsRatings_User'
CREATE INDEX [IX_FK_HotelsRatings_User]
ON [dbo].[HotelsRatings]
    ([UserId]);
GO

-- Creating foreign key on [UserId] in table 'Reservations'
ALTER TABLE [dbo].[Reservations]
ADD CONSTRAINT [FK_Reservations_User]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[Users]
        ([UserId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Reservations_User'
CREATE INDEX [IX_FK_Reservations_User]
ON [dbo].[Reservations]
    ([UserId]);
GO

-- Creating foreign key on [UserTypeId] in table 'Users'
ALTER TABLE [dbo].[Users]
ADD CONSTRAINT [FK_Users_UserType]
    FOREIGN KEY ([UserTypeId])
    REFERENCES [dbo].[UserTypes]
        ([UserTypeId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Users_UserType'
CREATE INDEX [IX_FK_Users_UserType]
ON [dbo].[Users]
    ([UserTypeId]);
GO

-- Creating foreign key on [Rooms_RoomId] in table 'UserRoomLikes'
ALTER TABLE [dbo].[UserRoomLikes]
ADD CONSTRAINT [FK_UserRoomLikes_Room]
    FOREIGN KEY ([Rooms_RoomId])
    REFERENCES [dbo].[Rooms]
        ([RoomId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Users_UserId] in table 'UserRoomLikes'
ALTER TABLE [dbo].[UserRoomLikes]
ADD CONSTRAINT [FK_UserRoomLikes_User]
    FOREIGN KEY ([Users_UserId])
    REFERENCES [dbo].[Users]
        ([UserId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserRoomLikes_User'
CREATE INDEX [IX_FK_UserRoomLikes_User]
ON [dbo].[UserRoomLikes]
    ([Users_UserId]);
GO

-- Creating foreign key on [Rooms1_RoomId] in table 'UserRoomViews'
ALTER TABLE [dbo].[UserRoomViews]
ADD CONSTRAINT [FK_UserRoomViews_Room]
    FOREIGN KEY ([Rooms1_RoomId])
    REFERENCES [dbo].[Rooms]
        ([RoomId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Users1_UserId] in table 'UserRoomViews'
ALTER TABLE [dbo].[UserRoomViews]
ADD CONSTRAINT [FK_UserRoomViews_User]
    FOREIGN KEY ([Users1_UserId])
    REFERENCES [dbo].[Users]
        ([UserId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserRoomViews_User'
CREATE INDEX [IX_FK_UserRoomViews_User]
ON [dbo].[UserRoomViews]
    ([Users1_UserId]);
GO

-- Creating foreign key on [webpages_Roles_RoleId] in table 'webpages_UsersInRoles'
ALTER TABLE [dbo].[webpages_UsersInRoles]
ADD CONSTRAINT [FK_webpages_UsersInRoles_webpages_Roles]
    FOREIGN KEY ([webpages_Roles_RoleId])
    REFERENCES [dbo].[webpages_Roles]
        ([RoleId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Users_UserId] in table 'webpages_UsersInRoles'
ALTER TABLE [dbo].[webpages_UsersInRoles]
ADD CONSTRAINT [FK_webpages_UsersInRoles_User]
    FOREIGN KEY ([Users_UserId])
    REFERENCES [dbo].[Users]
        ([UserId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_webpages_UsersInRoles_User'
CREATE INDEX [IX_FK_webpages_UsersInRoles_User]
ON [dbo].[webpages_UsersInRoles]
    ([Users_UserId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------